﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FGK
{
    class Program
    {
        static void Main(string[] args)
        {
            Plane P1 = new Plane(new Vector3(0, 320, 0), new Vector3(0, -1, 0));
            P1.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(0.6, 0.6, 0.6), new LightIntensity(1.0, 1.0, 1.0)));
            Plane P2 = new Plane(new Vector3(0, -320, 0), new Vector3(0, 1, 0));
            P2.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(0.9, 0.9, 0.9), new LightIntensity(1.0, 1.0, 1.0)));
            Plane P3 = new Plane(new Vector3(-320, 0, 0), new Vector3(1, 0, 0));
            P3.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(1.0, 0.0, 0.0), new LightIntensity(1.0, 1.0, 1.0)));
            Plane P4 = new Plane(new Vector3(320, 0, 0), new Vector3(-1, 0, 0));
            P4.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(0.0, 0.0, 1.0), new LightIntensity(1.0, 1.0, 1.0)));
            Plane P5 = new Plane(new Vector3(0, 0, -320), new Vector3(0, 0, 1));
            P5.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(1.0, 1.0, 1.0), new LightIntensity(1.0, 1.0, 1.0)));
            Plane P6 = new Plane(new Vector3(0, 0, 320), new Vector3(0, 0, -1));
            P6.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(1.0, 1.0, 1.0), new LightIntensity(1.0, 1.0, 1.0)));
            Sphere S1 = new Sphere(new Vector3(-120, -240, -230), 80);
            Sphere S2 = new Sphere(new Vector3(120, -240, -120), 80);
            Sphere S3 = new Sphere(new Vector3(140, -100, -220), 30);
            Sphere S4 = new Sphere(new Vector3(-200, -280, -140), 40);

            //Triangle t1 = new Triangle(new Vector3(120, 120, -310), new Vector3(-120, 120, -310), new Vector3(-120, -120, -310));
            //Triangle t2 = new Triangle(new Vector3(-120, -120, -310), new Vector3(120, -120, -310), new Vector3(120, 120, -310));
            //Texture recT = new Texture("tex.bmp");

            //lalala wtf!?
            //for (int i = 0; i < 20; i++)
            //{
            //    for (int j = 0; j < 20; j++)
            //    {
            //        recT.SetPixel(i, j, new LightIntensity(0.0, 1.0, 0.0));
            //    }
            //};

            
            //t1.setMaterial(new Material(recT));
            //t2.setMaterial(new Material(recT));
            
            S1.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(1.0, 1.0, 1.0), new LightIntensity(1.0, 1.0, 1.0), 10.0f, 1.52f, (int)Material.Types.mirror));
            S2.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(1.0, 1.0, 1.0), new LightIntensity(1.0, 1.0, 1.0), 10.0f, 1.52f, (int)Material.Types.mirror));
            S3.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(1.0, 0.9, 0.0), new LightIntensity(1.0, 1.0, 1.0)));
            S4.setMaterial(new Material(new LightIntensity(0.0, 0.0, 0.0), new LightIntensity(0.0, 1.0, 0.0), new LightIntensity(1.0, 1.0, 1.0)));

            PointLight PL1 = new PointLight(new Vector3(0,315,-160),new LightIntensity(1.0,1.0,1.0));
            //PointLight PL2 = new PointLight(new Vector3(100, 0, 100));

            Scene scene = new Scene();

            scene.addObject(S1);
            scene.addObject(S2);
            //scene.addObject(S3);
            //scene.addObject(S4);

            scene.addObject(P1);
            scene.addObject(P2);
            scene.addObject(P3);
            scene.addObject(P4);
            scene.addObject(P5);
            scene.addObject(P6);

            //scene.addObject(t1);
            //scene.addObject(t2);

            scene.addLight(PL1);

            //OrthographicCamera cam1 = new OrthographicCamera(new Image(640, 640, 1.0f, 1.0f));
            PerspectiveCamera cam2 = new PerspectiveCamera(new Image(320, 320, 1.5f, 1.5f), new Vector3(0, 0, 300), new Vector3(0, 0, -1));
            //cam1.render(scene);
            //cam2.render(scene);

            PhotonMap map = new PhotonMap(1);
            PhotonMap mapCaustic = new PhotonMap(1);

            //cam2.renderWithPhotonMapping(scene, map);
            cam2.renderFinal(scene, map, mapCaustic);

            Console.WriteLine("\nDone! \nPress Any key to exit...");
            ConsoleKeyInfo ki = Console.ReadKey();
            if (ki.KeyChar == 13)
            {
                Console.WriteLine("That's not the Any key.");
                ki = Console.ReadKey();
                if (ki.KeyChar == 13)
                {
                    Console.WriteLine("That's [Enter].");
                    ki = Console.ReadKey();
                    if (ki.KeyChar == 13) Console.WriteLine("Stop it already!");
                    ki = Console.ReadKey();
                    if (ki.KeyChar == 13) Console.WriteLine("Press [Space].");
                    ki = Console.ReadKey();
                    if (ki.KeyChar == 32)
                    {
                        Console.WriteLine("\rI was just testing. \nIf you pressed [Enter], I would have let you go :P");
                        ki = Console.ReadKey();
                        if (ki.KeyChar == 13 || ki.KeyChar == 32) Console.WriteLine("\rNow I won't xD");
                        ki = Console.ReadKey();
                        if (ki.KeyChar == 13) Console.WriteLine("For a 'while' ;)");
                        int i = 15;
                        do
                        {
                            Console.ReadKey();
                            i--;
                            if (i == 14) Console.WriteLine("Keep pressing, though.");
                            if (i == 10) Console.WriteLine("Well you're almost there.");
                            if (i == 5) Console.WriteLine("It's been fun :)");
                            if (i == 1) Console.WriteLine("Bye :(");
                        }
                        while (i > 0);
                    }
                    else if (ki.KeyChar == 13)
                    {
                        Console.WriteLine("I said [Space], fool!");
                        ki = Console.ReadKey();
                        if (ki.KeyChar == 13)
                        {
                            Console.WriteLine("I can already tell I don't like you.");
                            ki = Console.ReadKey();
                            if (ki.KeyChar == 13)
                            {
                                Console.WriteLine("Fine! Go away!");
                                ki = Console.ReadKey();
                            }
                            else if (ki.KeyChar == 32)
                            {
                                Console.WriteLine("\rYou got there in the end. Bye.");
                                ki = Console.ReadKey();
                            }
                        }
                        else if (ki.KeyChar == 32)
                        {
                            Console.WriteLine("\rBetter. Good bye :)");
                            ki = Console.ReadKey();
                        }
                    }
                }
                

            }

        }
    }
}
